package org.com.wlc.cglibproxy;

import org.com.wlc.jdkproxy.JdkHandler;
import org.com.wlc.proxy.Marry;
import org.com.wlc.proxy.Me;

/**
 * @author 王立朝
 * @description cglib动态代理测试
 * @date 2021-11-29 11:01:47
 */
public class CglibProxyTest {

    public static void main(String[] args) {
        CglibProxyTest cglibProxyTest = new CglibProxyTest();
        cglibProxyTest.test02();
        System.out.println("==============");
        cglibProxyTest.test01();
        System.out.println("==============");
        // 报错
        cglibProxyTest.test03();
    }

    public void test03(){
        A  a = new A();
        JdkHandler jdkHandler = new JdkHandler(a);
        A a1 = (A) jdkHandler.getProxy();
        a1.test();

        System.out.println();

    }
    /**
     * cglib 目标对象没有实现接口
     */
    public void test02(){
        A a = new A();
        CglibProxyManager cglibProxyManager = new CglibProxyManager(a);
        A a1 = (A)cglibProxyManager.getProxy();
        a1.test();

    }
    /**
     * 有参数的cglib代理
     */
    public void test01(){
        // 目标对象
        Me me = new Me();
        // 代理类
        CglibProxyManager cglibProxyManager = new CglibProxyManager(me);
        // 获取代理对象
        Marry marry = (Marry) cglibProxyManager.getProxy();
        marry.marry();
    }
}
